#! /bin/csh -f

setenv CDROM     $HOTMIXDIR/html/vendors/siteways/software

setenv PRODUCT   "LiveStream 1.1"
setenv TMP       /tmp/livestream
setenv LOGFILE   $TMP/install.log
setenv HOME      $TMP

#
# create temporary livestream directory
#
rm -fr /tmp/livestream >/dev/null
mkdir $TMP >/dev/null
mkdir $TMP/conf >/dev/null
chmod 755 $TMP/.
chmod -R a+rw $TMP/*
echo "*** `date`" >$LOGFILE
#echo -n "\007" >/dev/console

#
# find unused tcp port
#
setenv PORT `$CDROM/bin/probe`

#
# find hostname and domain
#
setenv HOSTNAME `$CDROM/bin/lookup`
setenv DOMAIN   `echo $HOSTNAME | sed 's/^[a-z-]*\./\./'`
if ($HOSTNAME == $DOMAIN ) then
   setenv DOMAIN all
endif
if ($HOSTNAME == "") then
   xconfirm -B Quit -t "The network should be up and running to install ${PRODUCT}"
   exit 1
endif

#
# create http server configuration
#
foreach configfile ($CDROM/lib/httpd.template/*)
   setenv CONF `basename $configfile`
   cat $configfile | \
   sed 's>$CDROM>'"$CDROM>g" | \
   sed 's>$TMP>'"$TMP>g" | \
   sed 's>$PORT>'"$PORT>g" | \
   sed 's>$HOSTNAME>'"$HOSTNAME>g" | \
   sed 's>$DOMAIN>'"$DOMAIN>g" | \
   grep -v "^#" >$TMP/conf/$CONF
end
echo "*** Server configuration created" >>$LOGFILE
#echo -n "\007" >/dev/console

#
# create config file
#
echo "#\n#\n# Created: `date`\n#" >$TMP/config.inf
echo "HOSTNAME=$HOSTNAME"     >>$TMP/config.inf
echo "DOMAIN=$DOMAIN"         >>$TMP/config.inf
echo "PORT=$PORT"             >>$TMP/config.inf
echo "CDROM=$CDROM"           >>$TMP/config.inf
$CDROM/bin/setup              >>$TMP/config.inf
#echo -n "\007" >/dev/console

#
# start http server
#
$CDROM/bin/httpd -d $TMP >>$LOGFILE

#
# allow httpd server to start
#
foreach n (1 2 3 4 5 6 7 8)
   sleep 2
   #echo -n "\007" >/dev/console
end

#
# connect running netscape browser to httpd server
#
$HOTMIXDIR/.bin/netscape/netscape.lock -remote "openURL(http://${HOSTNAME}:${PORT}/index.html, LiveStreamSetup)"
